<?php
header("Content-type: text/html; charset=utf-8");

$admin = true;
require_once('auth_req.inc.php');

$use_opt = false;

if($_GET['type'] == 'opt')
{
    $use_opt = true;
}


$rs = $dbh->query('select g_id, name from groups');


$alldb = $rs->fetchAll(PDO::FETCH_ASSOC);

foreach( $alldb as $key => $val)
{
    if ($use_opt)
    {
        echo "<option value='" . $val['g_id'] . "'>". $val['name'] ."</option>\n";
    }
    else
    {
        $response[$key]['id'] = $val['g_id'];
        $response[$key]['name'] = $val['name'];
    }
}

if (!$use_opt)
{
    echo json_encode($response);
}

?>
